package com.wyl.selenium.annotation;

import ch.qos.logback.core.pattern.ConverterUtil;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ClassUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;

import java.lang.reflect.Field;

/**
 * @Description
 * @Author WuYiLong
 * @Date 2023/11/21 17:07
 */
public class FieldTypeFactory {

    public static void convert(Object object) {
        Class<Object> clazz = ClassUtil.getClass(object);
        Field[] fields = ReflectUtil.getFields(clazz);
        for (Field field : fields) {
            field.setAccessible(true);
            FieldTypeConvert annotation = field.getAnnotation(FieldTypeConvert.class);
            if(annotation != null) {
                Class value = annotation.value();
                if(value.isAssignableFrom(String.class)) {
                    Object fieldValue = ReflectUtil.getFieldValue(object, field);
                    if(fieldValue != null) {
                        try {
                            String convert = Convert.convert(String.class, field);

                            field.set(object,String.class);
                        } catch (IllegalAccessException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }
}
